package com.teama4.shop.controller;

import com.teama4.shop.domain.*;
import com.teama4.shop.service.IndexService;
import com.teama4.shop.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;

@Controller
@RequestMapping("/index")
public class IndexController {
    @Autowired
    private IndexService indexService;

    @Autowired
    private UserService userService;

    static int user_number;
    static int order_number;
    static int store_number;

    private int user_id;

    @RequestMapping("/userList")
    public String user(Model model) {
        user_number = indexService.findUserNumber();
        order_number = indexService.findOrderNumber();
        store_number = indexService.findStoreNumber();
        model.addAttribute("user_number", user_number);
        model.addAttribute("order_number", order_number);
        model.addAttribute("store_number", store_number);
        List<User> list = indexService.listUser();
        model.addAttribute("list", list);
        return "/admin/user-list";
    }

    @RequestMapping("/orderList")
    public String order(Model model) {
        user_number = indexService.findUserNumber();
        order_number = indexService.findOrderNumber();
        store_number = indexService.findStoreNumber();
        model.addAttribute("user_number", user_number);
        model.addAttribute("order_number", order_number);
        model.addAttribute("store_number", store_number);
        List<Orders> list = indexService.listOrder();
        model.addAttribute("list", list);
        return "/admin/order-list";
    }

    @RequestMapping("/storeList")
    public String store(Model model){
        user_number = indexService.findUserNumber();
        order_number = indexService.findOrderNumber();
        store_number = indexService.findStoreNumber();
        model.addAttribute("user_number", user_number);
        model.addAttribute("order_number", order_number);
        model.addAttribute("store_number", store_number);
        List<Store> list = indexService.listStore();
        model.addAttribute("list", list);
        return "/admin/store-list";
    }

    @RequestMapping("/messageList")
    public String message(Model model){
        user_number = indexService.findUserNumber();
        order_number = indexService.findOrderNumber();
        store_number = indexService.findStoreNumber();
        model.addAttribute("user_number", user_number);
        model.addAttribute("order_number", order_number);
        model.addAttribute("store_number", store_number);
        List<Store> list = indexService.listMessage();
        model.addAttribute("list", list);
        return "/admin/admin-message-center";
    }

    @RequestMapping("/userVerifyList")
    public String userVerifyList(Model model){
        user_number = indexService.findUserNumber();
        order_number = indexService.findOrderNumber();
        store_number = indexService.findStoreNumber();
        model.addAttribute("user_number", user_number);
        model.addAttribute("order_number", order_number);
        model.addAttribute("store_number", store_number);
        List<User> list = indexService.listUnverifiedUser();
        model.addAttribute("list", list);
        return "/admin/admin-user-verify";
    }

    @RequestMapping("/commodityList")
    public String commodity(int id, Model model){
        List<Commodity> list = indexService.listCommodity(id);
        model.addAttribute("storeId",id);
        model.addAttribute("list", list);
        return "/merchant/commodity-list";
    }

    @RequestMapping("/merchantStoreList")
    public String merchantStoreList(Model model, int id) {
        user_id = id;
        List<Store> list = indexService.listMerchantStore(id);
        User user = userService.selectByPrimaryKey(user_id);
        model.addAttribute("list", list);
        model.addAttribute("user", user);
        return "/merchant/store-list";
    }

    @RequestMapping("/merchantOrderList")
    public String merchantOrderList(Model model) {
        List<Orders> list = indexService.listMerchantOrders(user_id);
        model.addAttribute("list", list);
        return "/merchant/order-list";
    }
}
